/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.publics;

import com.toedter.calendar.JDateChooser;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.List;
import javax.swing.*;
import main.ServicesList;
import model.publics.Supplier;
import model.publics.Suprincipal;
import org.apache.log4j.Logger;
import utility.NameValueList;
import utility.com.ComponentUtils;
import utility.com.TextComponentUtils;
import utility.typeSafe.EnumUtils;
import utility.typeSafe.InvoiceType;
import utility.typeSafe.ItemStatus;


public class SupplierFrm extends javax.swing.JDialog {
    
    private Supplier supplier;
    private Object oldValue, newValue;
    private List<NameValueList> invoiceList = EnumUtils.enumToNameValueList(InvoiceType.class);
    private List<NameValueList> statusList = EnumUtils.enumToNameValueList(ItemStatus.class);
    private static Logger log = Logger.getLogger(SupplierFrm.class);
    
    public SupplierFrm() {
        super(ServicesList.MAIN_FRAME, true);
        initComponents();
        initComponentsRules();
    }
        
    public int execute(int id) {
        setLocationRelativeTo(null);
        
        initForm();
        if (id!=0) { loadData(id); }

        setVisible(true);
        if (supplier!=null) {
        return supplier.getId();}
        else { return 0; }
    }

    private void initButtonState(boolean status){
        btnSave.setEnabled(status);
    }
    
    private void initForm(){
        supplier = new Supplier();
        
        txtNama.setText("");
        txtAC.setText("");
        txtACName.setText("");
        txtAlamat.setText("");
        txtBank.setText("");
        txtEmail.setText("");
        txtFax.setText("");
        txtKode.setText("");
        txtKontak.setText("");
        txtKota.setText("");
        txtLeadTime.setText("0");
        txtNpwp.setText("");
        txtNpwpAlamat.setText("");
        txtNpwpName.setText("");
        txtPhone.setText("");
        txtPos.setText("");
        txtSKP.setText("");
        txtTOP.setText("0");
        txtWebsite.setText("");
        chKunjungan01.setSelected(false);
        chKunjungan02.setSelected(false);
        chKunjungan03.setSelected(false);
        chKunjungan04.setSelected(false);
        chKunjungan05.setSelected(false);
        chKunjungan06.setSelected(false);
        chkHold.setSelected(false);
        chkOpenTOP.setSelected(false);
        cmbInvoice.setSelectedIndex(0);
        cmbJenis.setSelectedIndex(0);
        cmbKondisi.setSelectedIndex(0);
        dtpSKP.setDate(new java.util.Date());
        initButtonState(false);
    }
    
    private void setJadwal() {
        String jadwal = "";
        if(chKunjungan01.isSelected()) { jadwal = jadwal.concat("1"); }
        else { jadwal = jadwal.concat("0"); }
        
        if(chKunjungan02.isSelected()) { jadwal = jadwal.concat("1"); }
        else { jadwal = jadwal.concat("0"); }
        
        if(chKunjungan03.isSelected()) { jadwal = jadwal.concat("1"); }
        else { jadwal = jadwal.concat("0"); }
        
        if(chKunjungan04.isSelected()) { jadwal = jadwal.concat("1"); }
        else { jadwal = jadwal.concat("0"); }
        
        if(chKunjungan05.isSelected()) { jadwal = jadwal.concat("1"); }
        else { jadwal = jadwal.concat("0"); }
        
        if(chKunjungan06.isSelected()) { jadwal = jadwal.concat("1"); }
        else { jadwal = jadwal.concat("0"); }
        
        supplier.getSuprincipal().setJadwal(jadwal);
    }
    
    private void getJadwal () {
        if (supplier.getSuprincipal()!=null) {
            String jadwal = supplier.getSuprincipal().getJadwal();
            if (jadwal == null || jadwal.isEmpty()) {
                jadwal = "000000";
            }

            String j01 = jadwal.substring(0, 1);
            String j02 = jadwal.substring(1, 2);
            String j03 = jadwal.substring(2, 3);
            String j04 = jadwal.substring(3, 4);
            String j05 = jadwal.substring(4, 5);
            String j06 = jadwal.substring(5, 6);

            chKunjungan01.setSelected("1".equals(j01) ? true:false);
            chKunjungan02.setSelected("1".equals(j02) ? true:false);
            chKunjungan03.setSelected("1".equals(j03) ? true:false);
            chKunjungan04.setSelected("1".equals(j04) ? true:false);
            chKunjungan05.setSelected("1".equals(j05) ? true:false);
            chKunjungan06.setSelected("1".equals(j06) ? true:false);
        }
    }
    
    private void validasi(){
        boolean valid;
        
        valid = txtNama.getText().equals("") ? false:true;
        if (!valid) {
            JOptionPane.showMessageDialog(this, "Nama belum diisi.!"
            ,"Warinig",JOptionPane.WARNING_MESSAGE);}
        
        if (valid) { saveData(); }
    }
    
    private void saveData(){
        Suprincipal principal = supplier.getSuprincipal();
        if (principal==null) { principal = new Suprincipal(); }
        
        supplier.setSuprincipal(principal);
        principal.setSupplier(supplier);
        
        supplier.setAlamat(txtAlamat.getText());
        supplier.setEmail(txtEmail.getText());
        supplier.setFax(txtFax.getText());
        supplier.setKode(txtKode.getText());
        supplier.setKodePos(txtPos.getText());
        supplier.setKontak(txtKontak.getText()); 
        supplier.setKota(txtKota.getText());
        supplier.setNama(txtNama.getText());
        supplier.setPhone(txtPhone.getText());
        supplier.setWebsite(txtWebsite.getText());
                
        principal.setAcId(txtAC.getText());
        principal.setAcNama(txtACName.getText());
        principal.setBank(txtBank.getText());
        principal.setHoldPayment(chkHold.isSelected());
        principal.setOpenTop(chkOpenTOP.isSelected());
        principal.setPkp(cmbJenis.getSelectedIndex()==0 ? true:false);
        
        principal.setJenisInvoice (((NameValueList) cmbInvoice.getSelectedItem()).getKey().toString());
        principal.setKondisiBarang (((NameValueList) cmbKondisi.getSelectedItem()).getKey().toString());
       
        int leadTime=0;
        if (!txtLeadTime.getText().isEmpty()) {
            leadTime = Integer.parseInt(txtLeadTime.getText());
        }
        
        int top=0;
        if (!txtTOP.getText().isEmpty()) {
            top = Integer.parseInt(txtTOP.getText());
        }
        
        principal.setLeadTime(leadTime);
        principal.setTop(top);
        principal.setNpwp(txtNpwp.getText());
        principal.setNpwpAlamat(txtNpwpAlamat.getText());
        principal.setNpwpNama(txtNpwpName.getText());
        principal.setSkp(txtSKP.getText());
        principal.setSkpDate(dtpSKP.getDate());
        setJadwal();
        
        boolean saved = false;
        try{
            saved = ServicesList.getSupplierService().save(supplier);
            
        } catch(Exception ex){
            log.error(ex);
            JOptionPane.showMessageDialog(this, "Data gagal disimpan!"
            ,"Error",JOptionPane.ERROR_MESSAGE);
        }
        
        initButtonState(!saved);
    }
    
    private void loadData(int id){
        
        supplier = ServicesList.getSupplierService().getSupplier(id);
        if (supplier != null) {
            if (supplier.getSuprincipal()!=null) {
                txtAC.setText(supplier.getSuprincipal().getAcId());
                txtACName.setText(supplier.getSuprincipal().getAcNama());
                txtBank.setText(supplier.getSuprincipal().getBank());
                txtLeadTime.setText(supplier.getSuprincipal().getLeadTime().toString());
                txtNpwp.setText(supplier.getSuprincipal().getNpwp());
                txtNpwpAlamat.setText(supplier.getSuprincipal().getNpwpAlamat());
                txtNpwpName.setText(supplier.getSuprincipal().getNpwpNama());
                txtSKP.setText(supplier.getSuprincipal().getSkp());
                txtTOP.setText(supplier.getSuprincipal().getTop().toString());
                chkHold.setSelected(supplier.getSuprincipal().getHoldPayment());
                chkOpenTOP.setSelected(supplier.getSuprincipal().getOpenTop());
                dtpSKP.setDate(supplier.getSuprincipal().getSkpDate());
                cmbJenis.setSelectedIndex(supplier.getSuprincipal().getPkp() ? 0: 1);
                cmbInvoice.setSelectedIndex(NameValueList.indexOf(invoiceList, supplier.getSuprincipal().getJenisInvoice()));
                cmbKondisi.setSelectedIndex(NameValueList.indexOf(statusList, supplier.getSuprincipal().getKondisiBarang()));
            }
            txtAlamat.setText(supplier.getAlamat());
            txtEmail.setText(supplier.getEmail());
            txtFax.setText(supplier.getFax());
            txtKode.setText(supplier.getKode());
            txtKontak.setText(supplier.getKontak());
            txtKota.setText(supplier.getKota());
            txtNama.setText(supplier.getNama());
            txtPhone.setText(supplier.getPhone());
            txtPos.setText(supplier.getKodePos());
            txtWebsite.setText(supplier.getWebsite());
            getJadwal();
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        btnAdd = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnClose = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        txtKode = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtNama = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAlamat = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        txtKota = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtPos = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtPhone = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtFax = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtWebsite = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtKontak = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        txtNpwp = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtNpwpName = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtNpwpAlamat = new javax.swing.JTextArea();
        jLabel14 = new javax.swing.JLabel();
        txtSKP = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtAC = new javax.swing.JTextField();
        txtACName = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtBank = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        txtLeadTime = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        txtTOP = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        chkOpenTOP = new javax.swing.JCheckBox();
        chkHold = new javax.swing.JCheckBox();
        jLabel20 = new javax.swing.JLabel();
        cmbJenis = new javax.swing.JComboBox();
        cmbInvoice = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        cmbKondisi = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();
        chKunjungan01 = new javax.swing.JCheckBox();
        chKunjungan02 = new javax.swing.JCheckBox();
        chKunjungan03 = new javax.swing.JCheckBox();
        chKunjungan06 = new javax.swing.JCheckBox();
        chKunjungan05 = new javax.swing.JCheckBox();
        chKunjungan04 = new javax.swing.JCheckBox();
        dtpSKP = new com.toedter.calendar.JDateChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setSize(this.getWidth(), 50);

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edit_add.png"))); // NOI18N
        btnAdd.setText("Tambah");
        btnAdd.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnAdd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        jToolBar1.add(btnAdd);

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/filesave.png"))); // NOI18N
        btnSave.setText("Simpan");
        btnSave.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });
        jToolBar1.add(btnSave);

        btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cancel.png"))); // NOI18N
        btnClose.setText("Close");
        btnClose.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnClose.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });
        jToolBar1.add(btnClose);

        txtKode.setText("jTextField1");
        txtKode.setName("txtKode");

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Kode :");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Nama :");

        txtNama.setText("jTextField1");
        txtNama.setName("txtNama");

        txtAlamat.setColumns(20);
        txtAlamat.setLineWrap(true);
        txtAlamat.setRows(5);
        txtAlamat.setTabSize(2);
        txtAlamat.setName("txtAlamat");
        txtAlamat.setNextFocusableComponent(txtKota);
        jScrollPane1.setViewportView(txtAlamat);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Alamat :");

        txtKota.setText("jTextField1");
        txtKota.setName("txtKota"); // NOI18N

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Kota :");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Kode Pos :");

        txtPos.setText("jTextField1");
        txtPos.setName("txtPos"); // NOI18N

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Phone :");

        txtPhone.setText("jTextField1");
        txtPhone.setName("txtPos"); // NOI18N

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Fax :");

        txtFax.setText("jTextField1");
        txtFax.setName("txtFax"); // NOI18N

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Website :");

        txtWebsite.setText("jTextField1");
        txtWebsite.setName("txtWebsite"); // NOI18N

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Email :");

        txtEmail.setText("jTextField1");
        txtEmail.setName("txtEmail"); // NOI18N

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Kontak :");

        txtKontak.setText("jTextField1");
        txtKontak.setName("txtKontak"); // NOI18N
        txtKontak.setNextFocusableComponent(btnSave);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(txtKode, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(184, 184, 184))
                        .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtPos, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtKontak, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtEmail, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtKota, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtPhone, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtFax, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtWebsite, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtKota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtWebsite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtKontak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addContainerGap(85, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Identitas", jPanel1);

        txtNpwp.setText("jTextField1");
        txtNpwp.setName("txtNpwp");

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("NPWP :");

        txtNpwpName.setText("jTextField1");
        txtNpwpName.setName("txtNpwpName");

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText("Nama NPWP :");

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText("Alamat NPWP :");

        txtNpwpAlamat.setColumns(20);
        txtNpwpAlamat.setLineWrap(true);
        txtNpwpAlamat.setRows(5);
        txtNpwpAlamat.setTabSize(2);
        txtNpwpAlamat.setName("txtNpwpAlamat");
        txtNpwpAlamat.setNextFocusableComponent(txtSKP);
        jScrollPane2.setViewportView(txtNpwpAlamat);

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel14.setText("No SKP :");

        txtSKP.setText("jTextField1");
        txtSKP.setName("txtSKP");

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel15.setText("No Rekening :");

        txtAC.setText("jTextField1");
        txtAC.setName("txtAC");

        txtACName.setText("jTextField1");
        txtACName.setName("txtACName");

        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel16.setText("Giro Atas Nama :");

        txtBank.setText("jTextField1");
        txtBank.setName("txtBank");

        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel17.setText("Bank :");

        txtLeadTime.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtLeadTime.setText("jTextField1");
        txtLeadTime.setName("txtLeadTime");

        jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel18.setText("Lead Time :");

        txtTOP.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTOP.setText("jTextField1");
        txtTOP.setName("txtTOP");

        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel19.setText("TOP :");

        chkOpenTOP.setText(" : Open TOP");
        chkOpenTOP.setName("chkOpenTOP");

        chkHold.setText(" : Tahan Pembayaran");
        chkHold.setName("chkHold");

        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel20.setText("Jenis :");

        cmbJenis.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PKP", "NON PKP" }));
        cmbJenis.setName("cmbJenis");

        cmbInvoice.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SAAT TAGIH", "SAAT KIRIM" }));
        cmbInvoice.setName("cmbInvoice");

        jLabel21.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel21.setText("Invoice :");

        jLabel22.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel22.setText("Kondisi Barang :");

        cmbKondisi.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "RETUR", "TUKAR GULING", "PUTUS" }));
        cmbKondisi.setName("cmbKondisi");

        jLabel23.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel23.setText("Kunjungan :");

        chKunjungan01.setText("Senin");
        chKunjungan01.setName("chKunjungan01");

        chKunjungan02.setText("Selasa");
        chKunjungan02.setName("chKunjungan02");

        chKunjungan03.setText("Rabu");
        chKunjungan03.setName("chKunjungan03");

        chKunjungan06.setText("Sabtu");
        chKunjungan06.setName("chKunjungan06");

        chKunjungan05.setText("Jumat");
        chKunjungan05.setName("chKunjungan05");

        chKunjungan04.setText("Kamis");
        chKunjungan04.setName("chKunjungan04");

        dtpSKP.setDateFormatString("d MM yyyy");
        dtpSKP.setName("dtpSKP"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel23, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel22, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel18, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel16, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel20, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbKondisi, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtTOP, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkOpenTOP))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtLeadTime, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chkHold))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chKunjungan01)
                            .addComponent(chKunjungan04))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(chKunjungan02)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chKunjungan03))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(chKunjungan05)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chKunjungan06))))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(cmbJenis, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel21)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cmbInvoice, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(txtNpwp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtNpwpName, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtBank, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                        .addComponent(txtACName, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(txtSKP, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(dtpSKP, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(txtAC, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(cmbJenis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbInvoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNpwp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNpwpName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtSKP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel14))
                    .addComponent(dtpSKP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtACName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtBank, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLeadTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(chkHold))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTOP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(chkOpenTOP))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(cmbKondisi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(chKunjungan01)
                    .addComponent(chKunjungan02)
                    .addComponent(chKunjungan03))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chKunjungan04)
                    .addComponent(chKunjungan05)
                    .addComponent(chKunjungan06))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Principal", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        initForm();
        txtKode.requestFocus();
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        dispose();
    }//GEN-LAST:event_btnCloseActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        validasi();
    }//GEN-LAST:event_btnSaveActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnSave;
    private javax.swing.JCheckBox chKunjungan01;
    private javax.swing.JCheckBox chKunjungan02;
    private javax.swing.JCheckBox chKunjungan03;
    private javax.swing.JCheckBox chKunjungan04;
    private javax.swing.JCheckBox chKunjungan05;
    private javax.swing.JCheckBox chKunjungan06;
    private javax.swing.JCheckBox chkHold;
    private javax.swing.JCheckBox chkOpenTOP;
    private javax.swing.JComboBox cmbInvoice;
    private javax.swing.JComboBox cmbJenis;
    private javax.swing.JComboBox cmbKondisi;
    private com.toedter.calendar.JDateChooser dtpSKP;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField txtAC;
    private javax.swing.JTextField txtACName;
    private javax.swing.JTextArea txtAlamat;
    private javax.swing.JTextField txtBank;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFax;
    private javax.swing.JTextField txtKode;
    private javax.swing.JTextField txtKontak;
    private javax.swing.JTextField txtKota;
    private javax.swing.JTextField txtLeadTime;
    private javax.swing.JTextField txtNama;
    private javax.swing.JTextField txtNpwp;
    private javax.swing.JTextArea txtNpwpAlamat;
    private javax.swing.JTextField txtNpwpName;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtPos;
    private javax.swing.JTextField txtSKP;
    private javax.swing.JTextField txtTOP;
    private javax.swing.JTextField txtWebsite;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setVisible(boolean value) {
        super.setVisible(value);
        txtKode.requestFocusInWindow();
    }
    
    public void moveNext() {
        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        manager.focusNextComponent();
    }
    
    class ActionKeyListener implements KeyListener {
        @Override public void keyTyped(KeyEvent e) {} 
        @Override public void keyReleased(KeyEvent e) {}
        
        @Override public void keyPressed(KeyEvent e) {
            switch (e.getKeyCode()) { 
                case KeyEvent.VK_TAB: 
                    switch (e.getComponent().getName()) {
                        case "txtAlamat": moveNext();break;
                        case "txtNpwpAlamat": moveNext();break;
                    }
                                        
                    break; 
                case KeyEvent.VK_ENTER: moveNext(); break; 
            }
        }
    }
    
    class ActionFocusGained implements FocusListener {
        @Override public void focusGained(FocusEvent e) { 
            Component componen = (Component) e.getSource(); 
            if (componen instanceof JTextField) { oldValue = ((JTextField) componen).getText();
            }else if (componen instanceof JComboBox) { oldValue = ((JComboBox) componen).getSelectedIndex();
            }else if (componen instanceof JCheckBox) { oldValue = ((JCheckBox) componen).isSelected();
            }else if (componen instanceof JTextArea) { oldValue = ((JTextArea) componen).getText();
            }else if (componen instanceof JDateChooser) { oldValue = ((JDateChooser) componen).getDate(); }
        }
        
        @Override public void focusLost(FocusEvent e) {
            Component componen = (Component) e.getSource(); 
            if (componen instanceof JTextField) { newValue = ((JTextField) componen).getText();
            }else if (componen instanceof JComboBox) { newValue = ((JComboBox) componen).getSelectedIndex();
            }else if (componen instanceof JCheckBox) { newValue = ((JCheckBox) componen).isSelected();
            }else if (componen instanceof JTextArea) { newValue = ((JTextArea) componen).getText();
            }else if (componen instanceof JDateChooser) { newValue = ((JDateChooser) componen).getDate(); }
            if (!newValue.equals(oldValue)) { initButtonState(true); }
        }
    }
    
    private void initComponentsRules() {
        btnClose.registerKeyboardAction(btnAdd.getActionForKeyStroke(
            KeyStroke.getKeyStroke(KeyEvent .VK_SPACE, 0, false)), KeyStroke.getKeyStroke(KeyEvent .VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);
 
        btnClose.registerKeyboardAction(btnAdd.getActionForKeyStroke(
            KeyStroke.getKeyStroke(KeyEvent .VK_SPACE, 0, true)), KeyStroke.getKeyStroke(KeyEvent .VK_ENTER, 0, true), JComponent.WHEN_FOCUSED);
        
        btnAdd.registerKeyboardAction(btnAdd.getActionForKeyStroke(
            KeyStroke.getKeyStroke(KeyEvent .VK_SPACE, 0, false)), KeyStroke.getKeyStroke(KeyEvent .VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);

        btnAdd.registerKeyboardAction(btnAdd.getActionForKeyStroke(
            KeyStroke.getKeyStroke(KeyEvent .VK_SPACE, 0, true)), KeyStroke.getKeyStroke(KeyEvent .VK_ENTER, 0, true), JComponent.WHEN_FOCUSED);

        btnSave.registerKeyboardAction(btnSave.getActionForKeyStroke(
            KeyStroke.getKeyStroke(KeyEvent .VK_SPACE, 0, false)), KeyStroke.getKeyStroke(KeyEvent .VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);
 
        btnSave.registerKeyboardAction(btnSave.getActionForKeyStroke(
            KeyStroke.getKeyStroke(KeyEvent .VK_SPACE, 0, true)), KeyStroke.getKeyStroke(KeyEvent .VK_ENTER, 0, true), JComponent.WHEN_FOCUSED);
        
        cmbInvoice.setModel(ComponentUtils.getDefaultComboBoxModel(invoiceList));
        cmbKondisi.setModel(ComponentUtils.getDefaultComboBoxModel(statusList));
        
        TextComponentUtils.setNumericTextOnly(txtTOP);
        TextComponentUtils.setNumericTextOnly(txtLeadTime);

        txtKode.addKeyListener(new ActionKeyListener());
        txtKode.addFocusListener(new ActionFocusGained());
        txtAC.addKeyListener(new ActionKeyListener());
        txtAC.addFocusListener(new ActionFocusGained());
        txtACName.addKeyListener(new ActionKeyListener());
        txtACName.addFocusListener(new ActionFocusGained());
        txtBank.addKeyListener(new ActionKeyListener());
        txtBank.addFocusListener(new ActionFocusGained());
        txtEmail.addKeyListener(new ActionKeyListener());
        txtEmail.addFocusListener(new ActionFocusGained());
        txtFax.addKeyListener(new ActionKeyListener());
        txtFax.addFocusListener(new ActionFocusGained());
        txtKontak.addKeyListener(new ActionKeyListener());
        txtKontak.addFocusListener(new ActionFocusGained());
        txtKota.addKeyListener(new ActionKeyListener());
        txtKota.addFocusListener(new ActionFocusGained());
        txtLeadTime.addKeyListener(new ActionKeyListener());
        txtLeadTime.addFocusListener(new ActionFocusGained());
        txtNama.addKeyListener(new ActionKeyListener());
        txtNama.addFocusListener(new ActionFocusGained());
        txtNpwp.addKeyListener(new ActionKeyListener());
        txtNpwp.addFocusListener(new ActionFocusGained());
        txtNpwpName.addKeyListener(new ActionKeyListener());
        txtNpwpName.addFocusListener(new ActionFocusGained());
        txtPhone.addKeyListener(new ActionKeyListener());
        txtPhone.addFocusListener(new ActionFocusGained());
        txtPos.addKeyListener(new ActionKeyListener());
        txtPos.addFocusListener(new ActionFocusGained());
        txtSKP.addKeyListener(new ActionKeyListener());
        txtSKP.addFocusListener(new ActionFocusGained());
        txtWebsite.addKeyListener(new ActionKeyListener());
        txtWebsite.addFocusListener(new ActionFocusGained());
        txtTOP.addKeyListener(new ActionKeyListener());
        txtTOP.addFocusListener(new ActionFocusGained());
        txtNpwpAlamat.addKeyListener(new ActionKeyListener());
        txtAlamat.addKeyListener(new ActionKeyListener());
        dtpSKP.addKeyListener(new ActionKeyListener());
        cmbInvoice.addKeyListener(new ActionKeyListener());
        cmbJenis.addKeyListener(new ActionKeyListener());
        cmbKondisi.addKeyListener(new ActionKeyListener());
        chKunjungan01.addKeyListener(new ActionKeyListener());
        chKunjungan02.addKeyListener(new ActionKeyListener());
        chKunjungan03.addKeyListener(new ActionKeyListener());
        chKunjungan04.addKeyListener(new ActionKeyListener());
        chKunjungan05.addKeyListener(new ActionKeyListener());
        chKunjungan06.addKeyListener(new ActionKeyListener());
        chkHold.addKeyListener(new ActionKeyListener());
        chkOpenTOP.addKeyListener(new ActionKeyListener());
    }      
    
    // Add actions
//component.getActionMap().put(nextFocusAction.getValue(Action.NAME), nextFocusAction);
//component.getActionMap().put(prevFocusAction.getValue(Action.NAME), prevFocusAction);

// The actions



//public Action nextFocusAction = new AbstractAction("Move Focus Forwards") {
//    public void actionPerformed(ActionEvent evt) {
//        ((Component)evt.getSource()).transferFocus();
//    }
//};
//public Action prevFocusAction = new AbstractAction("Move Focus Backwards") {
//    public void actionPerformed(ActionEvent evt) {
//        ((Component)evt.getSource()).transferFocusBackward();
//    }
//};

}
